<!DOCTYPE html>
<html>

<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <link rel="shortcut icon" href="custom/images/favicon.ico?v=2" />
    <style>
        html,
        body {
            overflow: hidden;
            padding: 0px;
            margin: 0px;
        }
		
    </style>
<!-- <script src='../custom/libs/jquery-3.4.1.min.js'></script> -->
    <!-- <script src='../custom/libs/echarts.js'></script> -->
    <!-- <script src='../custom/libs/echarts.min.js'></script> -->
    <!-- <script src='../custom/libs/china.js'></script> -->

    <!-- <script src='../custom/configs/htconfig.js'></script> -->
    <!-- <script src='../libs/knU3sXefAa5Q.js'></script> -->
    <!-- <script src='../libs/ht.js'></script> -->
    <!-- <script src='../libs/buckle.js'></script> -->
    <!-- <script src='../libs/ht-edgetype.js'></script> -->
    <!-- <script src='../libs/ht-ui.js'></script> -->
    <!-- <script src='../libs/ht-vector.js'></script> -->
    <!-- <script src='../libs/ht-animation.js'></script> -->

    <!-- <script src='../custom/configs/urlConfig.js'></script> -->
    <script src='../libs/core/IZrowIfUVaXF.js'></script>
    <script src='../libs/core/VT3MIEkV8AKv.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/core/buckle.js'></script>
    <script src='../libs/core/ht-ui.js'></script>

    <script src='../libs/plugin/ht-edgetype.js'></script>
    <script src="../libs/plugin/ht-obj.js"></script>
    <script src='../libs/plugin/ht-form.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src='../libs/plugin/ht-animation.js'></script>
    <script src='../configs/htconfig.js'></script>
    <!-- <script src="../libs/china.js"></script> -->
    <script src="../libs/echarts.min.js"></script>
    <script src='../libs/echarts.js'></script>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src='../libs/echarts.js'></script>
    <script src='../libs/buckle.js'></script>
    <script src='../libs/knU3sXefAa5Q.js'></script>

        <script src="../configs/urlConfig.js"></script>    
<script>
        var startId = 0;//报警信息播放
        var maxPageNum=0;//报警信息播放
        var showTableData = [];
        var tabledata = [
            /*{
                "id": "123",
                "reason": "2019.06.09-17:03 张家口风电场 发电能力缺陷 5台"
            }*/
        ];//循环报警事故记录

        var dataModel = new ht.DataModel();
        var graphView;
        var dataModelLeft;
        var dataModelRight;

        var timer;
        var timerStop=0;
        var timeBarValue=0;//进度条
        var timerWindDataNum=0;//气象当前第几条数据
        var timerWindDataTotalNum=0;//气象数据条数

        /*
                function changeMapFlag(){
                    if(mapFlag==1){
                        changeMapClose();
                    }else{
                        changeMapOpen();
                    }
                }
        */
        //open打开地图定时刷新，ht暂停重新打开也打开定时刷新
        function changeMapOpen() {
            timeBarValue=0;
            timerWindDataNum=0;
            clearInterval(timer);
            dataModelLeft.getDataByTag('timebarBlock').s('2d.visible', true);
            dataModelLeft.getDataByTag('push').s('select.width',0);
            dataModelLeft.getDataByTag('back').s('select.width',0);
            dataModelLeft.getDataByTag('stop').s('select.width',0);
            timer=setInterval(function () {
                timeBarValue=timeBarValue+0.01;
                timerWindDataNum=timerWindDataNum+1;
                if(timerWindDataNum==timerWindDataTotalNum-1){
                    timerWindDataNum=0;
                }
                if(timeBarValue>1){
                    timeBarValue=0;
                }
                var length=dataModelLeft.getDataByTag('timeBar');
                length.a("pb.value",timeBarValue);
                // getWinddata(timerWindDataNum);
            },60 * 1000 * 10);
        }
        function changeMapClose() {
            timeBarValue=0;
            timerWindDataNum=0;
            clearInterval(timer);
        }
        function push() {
            timeBarValue=timeBarValue+0.04;
            timerWindDataNum=timerWindDataNum+4;
            if(timeBarValue>1){
                timeBarValue=0;
                timerWindDataNum=0;
            }
            if(timerWindDataNum==timerWindDataTotalNum-1){
                timeBarValue=0;
                timerWindDataNum=0;
            }
            var length=dataModelLeft.getDataByTag('timeBar');
            length.a("pb.value",timeBarValue);
        }
        function back() {
            timeBarValue=timeBarValue-0.04;
            timerWindDataNum=timerWindDataNum-4;
            console.log(timeBarValue);
            console.log(timerWindDataNum);
            if(timeBarValue<0){
                timeBarValue=0;
                timerWindDataNum=0;
            }
            if(timerWindDataNum<0){
                timeBarValue=0;
                timerWindDataNum=0;
            }
            var length=dataModelLeft.getDataByTag('timeBar');
            length.a("pb.value",timeBarValue);
        }
        function stop() {
            if(timerStop==0){
                timerStop=1;
                clearInterval(timer);
            }else{
                timerStop=0;
                timer=setInterval(function () {
                    timeBarValue=timeBarValue+0.01;
                    timerWindDataNum=timerWindDataNum+1;
                    if(timeBarValue>1){
                        timeBarValue=0;
                    }
                    if(timerWindDataNum==timerWindDataTotalNum-1){
                        timerWindDataNum=0;
                    }
                    var length=dataModelLeft.getDataByTag('timeBar');
                    length.a("pb.value",timeBarValue);
                    // getWinddata(timerWindDataNum);
                },60 * 1000 * 10);
            }
        }


        function init() {
            changeMapClose();
            document.getElementById("ht").innerHTML = "";
            var gd2 = new ht.graph.GraphView();
            gd2.addToDOM(document.getElementById("ht"));
            // gd2.setScrollBarVisible(false)
            ht.Default.xhrLoad('displays/冀北/资源评估与气象预警/气象2.json', function (text) {
                var json = ht.Default.parse(text);
                if (json.title) document.title = json.title;
                dataModel.deserialize(json);
            });
            graphView = new ht.graph.GraphView(dataModel);
            graphView.mp(function(e){
                if(e.property==='graphView'){
                    var ad = e.newValue;
                    if(ad.dm().getDataByTag("timebarBlock")!==undefined){
                        dataModelLeft=ad.dm();
                        getAllPowerError();
                        getWarningAccidentRecord();
                        running(tabledata);
                        //初始化表格
                        changeData(tabledata, startId, showTableData);//解决初始化空白
                        if(tabledata.length>4){
                            setInterval(function () {
                                startId = changeData(tabledata, startId, showTableData)
                            }, 3 * 1000);
                        }
                        changeMapOpen()
                    }
                    if(ad.dm().getDataByTag("yearTime1")!==undefined){
                        dataModelRight=ad.dm();
                        var date=new Date();
                        var year=date.getFullYear()-1;
                        ad.dm().getDataByTag("yearTime1").a('ht.value', year.toString());
                        getwindSpeedChart(year);
                    }
                }
            })
            graphView.addToDOM(gd2.getView());
            graphView.setScrollBarVisible(false);
        }
        //获取预测偏差
        function getAllPowerError(){
            $.ajax({
                type : "GET",
                async : false, //同步请求
                url : attributeConfig.url+"/epplatform/v1/resourceMeteorological/getAllPowerError",
                contentType: "application/json; charset=utf-8",
                success:function(data){
                    if(data.code==0){
                        console.log(data.data);
                        dataModelLeft.getDataByTag('AllPowerError').s('text', data.data+"(MW)");
                    }
                },
                error: function() {
                    console.log("请求预测偏差失败，请稍后再试！");
                }
            });
        }
        //获取滚动报警记录
        function getWarningAccidentRecord(){
            var stations=[];
            $.ajax({
                type : "GET",
                async : false, //同步请求
                url : attributeConfig.url+"/epplatform/v1/resourceMeteorological/getWarningAccidentRecord",
                contentType: "application/json; charset=utf-8",
                success:function(data){
                    if(data.code==0){
                        tabledata=[];
                        if(data.data.length==0){
                            var obj={
                                "id":"",
                                "reason":"暂无报警记录"
                            }
                            tabledata.push(obj);
                        }else{
                            data.data.forEach(function (e) {
                                var obj={
                                    "id":"",
                                    "reason":e.date+" "+e.area+" 地区有 "+e.num+" 个风电场存在 "+e.warning+""
                                }
                                tabledata.push(obj);

                            })
                        }
                        console.log(tabledata);
                    }else{
                        var obj={
                            "id":"",
                            "reason":"暂无报警记录"
                        }
                        tabledata.push(obj);
                    }
                },
                error: function() {
                    console.log("请求报警记录失败，请稍后再试！");
                }
            });
            return stations;
        }


        function running(tabledata) {
            if(tabledata.length==1){
                maxPageNum=1;
            }else if(tabledata.length==2){
                maxPageNum=2;
            }else if(tabledata.length==3){
                maxPageNum=3;
            }else{
                maxPageNum=4;
            }

            for (var i = 0; i < tabledata.length; i++) {
                var tmp = tabledata[i];
                tmp['id'] = i;
            }
            return tabledata;
        }
        //变换数据
        function changeData(tabledata, startId, showTableData) {
            showTableData = [];
            var flag = true;
            for (var i = 0; i < maxPageNum; i++) {
                if (startId + i >= tabledata.length) {
                    startId = 0;
                    flag = false;
                    // showTableData.splice(i - 1);
                    break;
                }
                showTableData[i] = tabledata[startId + i];
            }
            var table = dataModelLeft.getDataByTag('tt');
            table.a({
                'ht.dataSource': showTableData
            });
            if (flag) {
                startId = startId + maxPageNum;
            }
            return startId;
        }

        //右侧风向风速图
        function getwindSpeedChart(year){
            var obj={};
            $.ajax({
                type : "GET",
                async : false, //同步请求
                data:{
                    "year":year
                },
                url : attributeConfig.url+"/epplatform/v1/resourceMeteorological/getWholeWindSpeed",
                contentType: "application/json; charset=utf-8",
                success:function(data){
                    if(data.code==0){
                        obj=data.data;
                        dataModelRight.getDataByTag('windspeedLinechart').a("xData",obj.speedX);
                        dataModelRight.getDataByTag('windspeedLinechart').a("yData",obj.speedY);
                        var colorArr=["#3cd8b1","#34c8d1","#91a8ed","#b172ee","#d651a9","#ff4e6b","#ff734e","#ff9751","#ffa200","#ffc35d","#71e095","#8CEA00","#1AFD9C","#FFD700","#ff6867","#28FF28"];
                        var directionYArr=[];

                        obj.directionY.forEach(function (e,index) {
                            var itemObj={
                                "value": e,
                                "itemStyle": {
                                    "color": colorArr[index]
                                }
                            };
                            directionYArr.push(itemObj);
                        })
                        dataModelRight.getDataByTag('windroseChart').a("xData",obj.directionX);
                        dataModelRight.getDataByTag('windroseChart').a("yData",directionYArr);
                    }
                },
                error: function() {
                    console.log("请求城市失败，请稍后再试！");
                }
            });
            return obj;
        }
    </script>
</head>

<body onload='init()'>
    <div id="ht"></div>
</body>
</html>
